﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsMine.DomainObjects;
using Db4objects.Db4o;
using Db4objects.Db4o.Linq;

namespace NewsMine.FeedRepository
{
    public class DB4O_FeedRepositoryManager:IFeedDataProvider
    {

        #region MFeed CRUD

        //public void AddFeed(MFeed feed)
        //{
        //    using (IObjectContainer container = Db4oEmbedded.OpenFile("databaseFile.db4o"))
        //    {
        //        container.Store(feed);

        //    }
        //}

        //public void UpdateFeed(MFeed feed)
        //{
        //    //modified while it is offline...
        //}

        //public MFeed GetFeedByUID(long id)
        //{
        //    using (IObjectContainer container = Db4oEmbedded.OpenFile("databaseFile.db4o"))
        //    {
        //        var result = from MFeed f in container
        //                     where f.UID == id
        //                     select f;

        //        return result.FirstOrDefault<MFeed>();


        //    }
        //}

        //public void GetFeedByUrl(string url)
        //{
        //}

        //public void DisableFeed(MFeed feed)
        //{
        //}

        #endregion

        #region IFeedDataProvider Members

        public void AddFeed(MFeed feed)
        {
             using (IObjectContainer container = Db4oEmbedded.OpenFile("databaseFile.db4o"))
             {
                 container.Store(feed);

                 long id = container.Ext().GetID(feed);


             }
        }

        public void EditFeed(MFeed feed)
        {
            throw new NotImplementedException();
        }

        public bool IsFeedUrlIsExists(string url)
        {
            throw new NotImplementedException();
        }

        public MFeed GetFeedByUrl(string url)
        {
            throw new NotImplementedException();
        }

        public MFeed GetFeedByID(int feedID)
        {
             using (IObjectContainer container = Db4oEmbedded.OpenFile("databaseFile.db4o"))
             {
                 var result = from MFeed f in container
                              where f.UID == feedID
                              select f; 

                 return result.FirstOrDefault<MFeed>();


             }
        }

        public List<MFeed> GetFeedsByDomain(string domain)
        {
            throw new NotImplementedException();
        }

        public void DisableFeed(MFeed feed)
        {
            throw new NotImplementedException();
        }

        public void AddFeedItems(MFeed feed)
        {
            throw new NotImplementedException();
        }

        public void AddFeedItems(MFeed feed, List<MFeedItem> feedItems)
        {
            throw new NotImplementedException();
        }

        public void AddFeedItem(MFeed feed, MFeedItem feedItem)
        {
            throw new NotImplementedException();
        }

        public void EditFeedItem(MFeedItem feedItem)
        {
            throw new NotImplementedException();
        }

        public bool IsFeedItemIsExists(MFeedItem feedItem)
        {
            throw new NotImplementedException();
        }

        public List<MFeedItem> GetFeedItemsByFeedID(int feedID, int maxRecords)
        {
            throw new NotImplementedException();
        }

        public List<MFeedItem> GetFeedItemsByFeedID(int feedID, DateTime cutOffTime)
        {
            throw new NotImplementedException();
        }

        public List<MFeedItem> GetFeedItemsByFeedItemIDs(string feedItemIDs)
        {
            throw new NotImplementedException();
        }

        public MFeedItem GetFeedItemsByFeedItemID(int feedID, int feedItemID)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
